<?php
/***********************************************************************************
		This static class provides different services to manipulate the 
		application.xml file which is the configuration file of the application
***********************************************************************************/
public class MySqlApplicationConfigurator implements{
	/*******************************************************************************
			This function adds a new mysql connection in application.xml file
			@connectionId : Name/ID of this connection (i.e. "myconnection") 
			@databaseName   : Name of the database (i.e. "testdb")
			@hostAddress    : MySql Server host name , defalut is "localhost"
			@username       : Database Username , default is "root"
			@password		: Database Password, default is ""/no password
	*******************************************************************************/
	public static function addMySqlConnectionString($connectionId, $databaseName ,
	$hostAddress="localhost", $username="root", $password="" ){
	
		// reading from the current application.xml configuration file
		$applicationXml = new TXmlDocument();
		$applicationXml->loadFromFile("protected/application.xml");
		
		// getting the application.xml modules section
		$modules = $applicationXml->getElementByTagName("modules");
		
		// creating a new module for a new connection string
		$module = new TXmlElement("module");
		
		// setting the class and id of the new connection string module
		$module->setAttribute("class","System.Data.TDataSourceConfig");
		$module->setAttribute("id",$connectionId);
		
		// creating the database node for the new connection string module
		$database = new TXmlElement("database");
		$database->setAttribute("ConnectionString","mysql:host=".$hostAddress
								.";dbname=".$databaseName. ")";
		$database->setAttribute("Username",$username);
		$database->setAttribute("Password",$password);
		
		// adding the database node to the connection string module
		$module->Elements[] = $database;
		// adding the new connection string module to the modeles of applciation.xml
		$modules->Elements[] = $module; 
		
		// overwriting the new application.xml into another file
		$applicationXml->saveToFile("protected/application.xml");
	}
	
	/*******************************************************************************
			This function modifies a mysql connection in application.xml file
			@connectionId   : ID of this connection (i.e. "myconnection") 
			@databaseName   : Name of the database (i.e. "testdb")
			@hostAddress    : MySql Server host name , defalut is "localhost"
			@username       : Database Username , default is "root"
			@password		: Database Password, default is ""/no password
	*******************************************************************************/
	public static function changeConnectionString($connectionId, $newDatabaseName ,
	$newHostAddress="localhost", $newUsername="root", $newPassword="" ){
	
	}
	
	/*******************************************************************************
			This function modifies a mysql connection ID in application.xml file
			@connectionId   : ID of this connection (i.e. "myconnection") 
	*******************************************************************************/
	public static function changeConnectionId($newConnectionId){
	
	}
	
	/*******************************************************************************
			This function modifies a mysql connection host address in 
			application.xml file
			@hostAddress    : MySql Server host name , defalut is "localhost"
	*******************************************************************************/
	public static function changeConnectionHostAddress($newHostAddress){
	
	}
	
	/*******************************************************************************
			This function modifies a mysql connection Database Name
			in application.xml file
			@databaseName   : Name of the database (i.e. "testdb")
	*******************************************************************************/
	public static function changeConnectionDatabase($newDatabase){
	
	}
	
	/*******************************************************************************
			This function modifies a mysql connection Username in 
			application.xml file
			@username       : Database Username , default is "root"
	*******************************************************************************/
	public static function changeConnectionUsername($newUsername){
	
	}
	
	/*******************************************************************************
			This function modifies a mysql connection Password in
			application.xml file
			@password		: Database Password, default is ""/no password
	*******************************************************************************/
	public static function changeConnectionPassword($newPassword){
	
	}
	
}
?>